package de.revdev.llt.module.useradministrtaion;

import de.revdev.llt.module.learning.LearnStatusFCB;
import de.revdev.llt.module.classroom.Participants;
import de.revdev.llt.module.classroom.PrivateClassRoom;
import de.revdev.llt.module.classroom.PublicClassRoom;
import de.revdev.llt.module.interfaces.EntityInterface;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author f.lindermaier
 */
@Entity
@Table(name = "tbl_user")
public class User implements Serializable, EntityInterface {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    @Size(min = 2, max = 30)
    private String firstname;
    @NotNull
    @Size(min = 2, max = 50)
    private String lastname;
    @NotNull
//    @Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message = "Ungültige E-mail")
    private String email;
    @Temporal(javax.persistence.TemporalType.DATE)
    @NotNull
    private Date birthday;
    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
    private Address address;
    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    private Credential credential;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Participants> participants;
    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
    private PrivateClassRoom privateClassRoom;
    @OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)
    private List<PublicClassRoom> publicClassRooms;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<LearnStatusFCB> learnStatusFCBs;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Credential getCredential() {
        return credential;
    }

    public void setCredential(Credential credential) {
        this.credential = credential;
    }

    public PrivateClassRoom getPrivateClassRoom() {
        return privateClassRoom;
    }

    public void setPrivateClassRoom(PrivateClassRoom privateClassRoom) {
        this.privateClassRoom = privateClassRoom;
    }

    public List<PublicClassRoom> getPublicClassRooms() {
        return publicClassRooms;
    }

    public void setPublicClassRooms(List<PublicClassRoom> publicClassRooms) {
        this.publicClassRooms = publicClassRooms;
    }

    public List<Participants> getParticipants() {
        return participants;
    }

    public void setParticipants(List<Participants> participants) {
        this.participants = participants;
    }

    public List<LearnStatusFCB> getLearnStatusFCBs() {
        return learnStatusFCBs;
    }

    public void setLearnStatusFCBs(List<LearnStatusFCB> learnStatusFCBs) {
        this.learnStatusFCBs = learnStatusFCBs;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.revdev.llt.bean.entities.NewEntity[ id=" + id + " ]";
    }
}
